#ifndef layer_menu_chapter_h
#define layer_menu_chapter_h

#import "head.h"

#define CHAPTER_STATE_BOOK 0
#define CHAPTER_STATE_PAGE 1

typedef struct SContentsPageIndex_
{
	UICenterRect rect;
	int index;
}
SContentsPageIndex;

typedef struct SPage_
{
	CCSprite *image;
	CCSprite *dummy;
	CCSprite *flower;
	CCSprite *star_background;
	CCSprite *star[3]; /*0:heart;1:enemy;2:special*/
	std::vector<CCLabelBMFont *> label;

	/*contents page
	*/
	std::vector<SContentsPageIndex> page_index_table;
}
SPage;

typedef struct SBook_
{
	int index;
	int active_page_index;
	CCSprite *image;
	std::vector<SPage> pages;
	CGPoint book_position;
}
SBook;

@interface LayerMenuChapter : CCLayer
{
	CCMenuItemImage *itemBack_;

	std::vector<SBook> bookTable_;
	int selectBookIndex_;

	CGPoint start_;
	CGPoint drag_;
	CGPoint end_;

	UICenterRect readBookRect_;
	UICenterRect closeBookRect_;

	/*background
	*/
	CCSprite *background_;
	float backgroundMoveRatio_;

	/*flag
	*/
	int state_;
	bool flagTouchLock_;
	bool flagFunctionLock_;
	bool flagDrag_;
	bool flagSelectBookPage_;
	bool flagTurnToPage_;
	int turnToPageIndex_;
}

- (id)initLayerMenuChapter;
- (void)dealloc;
- (void)ccTouchesBegan:(NSSet *)Touch withEvent:(UIEvent *)Event;
- (void)ccTouchesMoved:(NSSet *)Touch withEvent:(UIEvent *)Event;
- (void)ccTouchesEnded:(NSSet *)Touch withEvent:(UIEvent *)Event;

- (CCLabelBMFont *)CreateTitleText:(NSString *)String;
- (CCLabelBMFont *)CreateContextText:(NSString *)String;

- (void)SelectMission:(int)MissionID;
- (void)BooksMove:(float)Offset;

- (void)ActionSelectBook:(int)Index;
- (void)ActionCloseBook;
- (void)ActionNextPage;
- (void)ActionPrevPage;
- (void)ActionSelectBookPage:(int)BookIndex And:(int)PageIndex;
- (void)ActionTurnToPage:(int)Index;

- (void)CallBackItemBack:(id)Sender;
- (void)CallBackItemBackActionOver:(id)Sender;

- (void)CallBackActionOpenOver:(id)Sender;
- (void)CallBackActionSelectOver:(id)Sender;

- (void)CallBackActionPageFadeOutOver:(id)Sender;
- (void)CallBackActionCloseOver:(id)Sender;
- (void)CallBackActionUnselectOver:(id)Sender;

- (void)CallBackActionNextPageOver:(id)Sender;
- (void)CallBackActionPrevPageOver:(id)Sender;

@end

#endif